<template>
	<view class="p-2">
		<view class="p-2 bg-white">
			<view class="text-primary mb-2 font-bold" style="font-size: 30rpx;">
				{{dictKey(app_bidding_status,biddingInfo.biddingStatus)}}
			</view>
			<view class="mb-2 font-bold" style="font-size: 30rpx;">{{biddingInfo.model}}</view>
			<view class="flex mb-2" v-if="biddingInfo.highSalePrice">
				<view>销售最高报价：</view>
				<view class="text-danger font-bold flex-1">￥{{biddingInfo.highSalePrice?biddingInfo.highSalePrice:0}}
				</view>
			</view>
			<view class="flex mb-2">
				<view>报价金额：</view>
				<view class="text-danger font-bold flex-1">￥{{biddingInfo.biddingPrice?biddingInfo.biddingPrice:0}}
				</view>
			</view>
			<view class="text-secondary font">{{parseTime(biddingInfo.createTime)}}</view>
			<u-gap height="1" bgColor="#eaeaea" marginTop="20rpx" marginBottom="20rpx"></u-gap>
			<view class="flex j-start a-center mb-2">
				<view class="text-secondary">IMEI：</view>
				<view class="mr-2 flex-1">{{biddingInfo.imei}}</view>
				<image src="@/static/images/fuzhi.png" mode="widthFix" class="svgmini"
					@click="utils.setClipboardData(biddingInfo.imei)"></image>
			</view>
			<view class="flex j-start a-center mb-2">
				<view class="text-secondary">参数：</view>
				<view v-if="!biddingInfo.memory&&!biddingInfo.colour&&!biddingInfo.network">-- </view>
				<view class="flex-1" v-else>{{biddingInfo.colour}}
					<block v-if="biddingInfo.colour">，</block>
					{{biddingInfo.memory}}
					<block v-if="biddingInfo.memory">G </block>
					<block v-if="biddingInfo.buy">，</block>
					{{biddingInfo.buy}}
				</view>

			</view>
			<view class="flex j-start mb-3">
				<view class="text-secondary">机况：</view>
				<view class="flex-1">{{biddingInfo.subrackDesc?biddingInfo.subrackDesc:'--'}}</view>
			</view>
			<view style="margin-bottom: 150rpx;">

				<image-preview :src="biddingInfo.reportImg" :multiple="true" width="660rpx" height="auto"
					mode="widthFix" />
			</view>

			<view style="position: fixed;bottom: 0;left: 0;width: 100%;z-index: 100;background-color: #fff;"
				class="p-3 mt-4" v-if="biddingInfo.biddingStatus==1">
				<view class="btn m-o col-5 rounded-40" style="height: 70rpx;" @click="handleQuote">立即报价</view>
			</view>
		</view>

		<u-popup :show="showPopup" @close="showPopup=false" mode="center" :round="10" closeable
			:closeOnClickOverlay="false">
			<view class="col-11 py-5 px-3">
				<view class="flex j-start a-center mb-3">
					<view class="text-right font-md" style="width:190rpx">最高报价：</view>
					<view class="font-lg" v-if="biddingInfo.highSalePrice">
						￥{{biddingInfo.highSalePrice?biddingInfo.highSalePrice:0}}</view>
					<view class="font-lg" v-else>￥{{biddingInfo.highChannelPrice?biddingInfo.highChannelPrice:0}}</view>
				</view>
				<view class="flex j-start mb-4">
					<view class="text-right font-md" style="width:190rpx">报价金额：</view>
					<view class="flex-1">
						<u--input placeholder="请输入报价金额" border="surround" v-model="formData.biddingPrice"></u--input>
						<view class="font-sm text-secondary mt-2">报价金额最小为最高报价+10元</view>
					</view>
				</view>
				<view class="flex j-start a-center mb-3" v-if="app_user_info.mobileConfig.indexOf('quote')!=-1">
					<view class="text-right font-md" style="width:190rpx">销售人员：</view>
					<view class="flex-1 flex j-sb a-center rounded-10"
						style="border: 1px solid #dadbde;padding: 16rpx 10rpx;" @click="showPicker=true">
						<view class="font" style="color: #333;" v-if="formData.bindSaleUserName">
							{{formData.bindSaleUserName}}
						</view>
						<view class="font" style="color: #c0c4cc;" v-if="!formData.bindSaleUserName">选择销售人员</view>
						<u-icon name="arrow-down" color="#c0c4cc" size="14"></u-icon>
					</view>
				</view>
				<view class="btn m-o col-5 rounded-40" style="height: 70rpx;" @click="handleSubmitQuote">确定</view>

			</view>
		</u-popup>

		<u-picker :show="showPicker" :columns="userColumns" keyName="userName" @confirm="confirmPicker"
			@cancel="cancelSearch"></u-picker>

	</view>
</template>

<script>
	import {
		biddingDetail,
		biddingQuotePrice
	} from '@/common/api/bidding.js'
	import {
		appUserLists
	} from '@/common/api/customer.js'
	export default {
		name: "",
		mixins: [],
		data() {
			return {

				showPopup: false,
				biddingInfo: {},

				showPicker: false,
				userColumns: [],
				formData: {
					id: '',
					biddingPrice: 0,
					bindSaleUserId: '',
					bindSaleUserName: ''
				}
			}
		},
		onLoad(option) {
			this.biddingStatus();
			if (option.id) {
				this.formData.id = option.id;
				this.getData();
			}
			this.getCustomerList()

		},
		watch: {},
		computed: {},
		methods: {
			getData() {
				biddingDetail(this.formData.id).then(res => {
					this.biddingInfo = res.data;
					this.biddingInfo.reportImg = res.data.reportImg ? res.data.reportImg.split(',') : []
					uni.setNavigationBarTitle({
						// title: this.dictKey(this.app_bidding_status,res.data.biddingStatus)
						title: this.biddingInfo.model
					});

				})
			},
			handleQuote() {
				this.showPopup = true;
				let biddingPrice
				if (this.biddingInfo.highSalePrice) {
					biddingPrice = this.biddingInfo.highSalePrice ? this.biddingInfo.highSalePrice : 0;
				} else {
					biddingPrice = this.biddingInfo.highChannelPrice ? this.biddingInfo.highChannelPrice : 0;
				}
				this.formData.biddingPrice = Number(biddingPrice) + 10

			},
			getCustomerList() {
				this.userColumns = []
				appUserLists({
					enabled: 0,
					userType: 3001
				}).then(res => {
					this.userColumns.push(res.data)
				})
			},
			confirmPicker(val) {
				this.formData.bindSaleUserName = val.value[0].userName;
				this.formData.bindSaleUserId = val.value[0].id;
				this.showPicker = false;
			},
			cancelSearch() {
				this.showPicker = false;
			},

			handleSubmitQuote() {
				let biddingPrice
				if (this.biddingInfo.highSalePrice) {
					biddingPrice = this.biddingInfo.highSalePrice ? this.biddingInfo.highSalePrice : 0;
				} else {
					biddingPrice = this.biddingInfo.highChannelPrice ? this.biddingInfo.highChannelPrice : 0;
				}
				if (Number(this.formData.biddingPrice) - Number(biddingPrice) < 10) {
					uni.$u.toast('报价金额最小为渠道最高报价+10元');
					return false
				}
				let str = /^[1-9]\d*$/;
				if (!str.test(this.formData.biddingPrice)) {
					uni.$u.toast('报价金额只能为正整数');
					return false
				}
				if (this.formData.bindSaleUserId == '') {
					this.formData.bindSaleUserId = this.app_user_info.id;
					this.formData.bindSaleUserName = this.app_user_info.userName;
				}
				biddingQuotePrice(this.formData).then(res => {
					this.showPopup = false;
					uni.$u.toast('报价成功');
					this.navigateBack();
				})
			}
		}
	}
</script>

<style lang="scss">
</style>